package read_input;
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.StringTokenizer;


public class CSVFileReader {
	String fileName="";
	String strLine;
	ArrayList <Double> closePrice = new ArrayList<Double>();
	public CSVFileReader(String fileName){
		this.fileName=fileName;
	}
	public CSVFileReader() {
	}
	
	public void readFile(){
		try {	
			BufferedReader br = new BufferedReader( new FileReader(fileName));
			StringTokenizer st = null;
			int lineNumber = 0;
			closePrice = new ArrayList<Double>();
			strLine= br.readLine();
			while (strLine != null){
				lineNumber++;
				st = new StringTokenizer(strLine, ","); //break comma separated line using ","
				int i=0;
				while(st.hasMoreTokens()){
					String token = st.nextToken();
					if (i==5){
						closePrice.add(Double.parseDouble(token));
						break;
					}
					i++;
				}
				strLine= br.readLine();
				
			}
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	
	//------------------- getters &&setters -------------------//
	public void setFileName(String newFileName)
	{
		this.fileName=newFileName;
	}
	public String getFileName(){
		return fileName;
	}
	
	public ArrayList<Double> getClosePrice(){
		return this.closePrice;
	}
	
	public void displayClosePrice(){
		for(int i=0;i<this.closePrice.size();i++){
			System.out.println(closePrice.get(i));
		}
	}
	
}